package com.atguigu.spzx.pay.controller;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.atguigu.spzx.common.exception.GuiguException;
import com.atguigu.spzx.model.entity.pay.PaymentInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.order.client.OrderClient;
import com.atguigu.spzx.pay.config.AlipayConfig;
import com.atguigu.spzx.pay.service.AlipayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author syh
 * @create 2023-09-05 13:40
 */
@Controller
@Tag(name = "支付宝支付模块")
@RequestMapping("/api/order/alipay")
@Slf4j
public class AlipayController {
    @Resource
    AlipayService alipayService;
    @Resource
    OrderClient orderClient;

    @Operation(summary = "异步通知")
    @PostMapping("/notify_url")
    @ResponseBody
    public String notifyUrl(@RequestParam Map<String,String> params){

     return alipayService.notifyUrl(params);


    }

    @Operation(summary = "同步通知:浏览器重定向默认以get方式访问")
    @GetMapping("/return_url")
    public String returnUrl(@RequestParam Map<String,String>params){
       return alipayService.returnUrl(params);
    }

    @Operation(summary = "提交支付")
    @GetMapping("/submitAlipay/{orderNo}")
    @ResponseBody
    public Result submitAlipay(@PathVariable("orderNo")Long orderNo){
        //查询订单相关的数据 支付宝构建表单时需要的数据
        //构建表单字符串返回
        String form=alipayService.submitAlipay(orderNo);
        return Result.build(form, ResultCodeEnum.SUCCESS);
    }
}
